#include "light.h"

Light &Light::init(void)
{
  enable.init();
  EEPROM.begin(4096);
  data.read();
  if(!data.checkValid(_validFlag))
  {
    data.init(_validFlag);
    data.write();
  }
  left.attach(_seLeftPin);
  right.attach(_seRightPin);
  left.write(data.leftDefault);
  right.write(data.rightDefault);
  return *this;
}

Light &Light::start(void)
{
  enable.enable();
  return *this;
}

Light &Light::finish(void)
{
  enable.disable();
  return *this;
}

Light &Light::leftOn(unsigned long nms)
{
  left.write(data.leftOn);
  _delay(nms);
  return *this;
}

Light &Light::leftOff(unsigned long nms)
{
  left.write(data.leftOff);
  _delay(nms);
  return *this;
}

Light &Light::leftReset(unsigned long nms)
{
  left.write(data.leftDefault);
  _delay(nms);
  return *this;
}

Light &Light::rightOn(unsigned long nms)
{
  right.write(data.rightOn);
  _delay(nms);
  return *this;
}

Light &Light::rightOff(unsigned long nms)
{
  right.write(data.rightOff);
  _delay(nms);
  return *this;
}

Light &Light::rightReset(unsigned long nms)
{
  right.write(data.rightDefault);
  _delay(nms);
  return *this;
}

Light &Light::on(unsigned long nms)
{
  leftOn();
  rightOn();
  _delay(nms);
  return *this;
}

Light &Light::off(unsigned long nms)
{
  leftOff();
  rightOff();
  _delay(nms);
  return *this;
}

Light &Light::reset(unsigned long nms)
{
  leftReset();
  rightReset();
  _delay(nms);
  return *this;
}

Light &Light::dataReset(void)
{
  data.init(_validFlag);
  return *this;
}
